package com.mp.ipm2020.admin.controller;

import com.mp.ipm2020.common.api.CommonResult;
import com.mp.ipm2020.mbg.dto.DeviceInfoData;
import com.mp.ipm2020.mbg.model.DeviceData;
import com.mp.ipm2020.mbg.service.DeviceDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther adidasshe@mp.cn
 * <p>
 * 设备数据 Controller
 */

@RestController
@Api(tags = "设备数据")
@RequestMapping("/device_data")
public class DeviceDataController {

    @Autowired
    private DeviceDataService deviceDataService;

    @ApiOperation("根据设备ID查询最新一条设备数据")
    @GetMapping("/{device_id}")
    public CommonResult getItem(@PathVariable String device_id) {
        DeviceData data = deviceDataService.getByDeviceId(device_id);
        return CommonResult.success(data);
    }

    @ApiOperation("所有设备及最新的数据信息")
    @GetMapping("/list")
    public CommonResult getList() {
        List<DeviceInfoData> list = deviceDataService.getAllDevice();
        return CommonResult.success(list);
    }
}
